  <template>
  <div>
    <!-- 项目筛选弹框 -->
    <mt-popup
      class="vm-screen-warp"
      v-model="popupVisible"
      position="right"
      v-if="type == 'projectPage'"
    >
      <div class="vm-require-warp" ref="popupWarpper">
        <div class="content">
          <div class="vm-require-screen-item">
            <h5>行业</h5>
            <ul class="vm-require-screen-list">
              <li :class="{'now': item.isActive}"
              v-for="(item, key) in screenData.industry"
              @click="selectedPublisher(screenData.industry, item)"
              :key="key"> {{ item.value }}
              </li>
            </ul>
          </div>
          <div class="vm-require-screen-item">
            <h5>阶段</h5>
            <ul class="vm-require-screen-list">
              <li
              :class="{'now': item.isActive}"
              v-for="(item, key) in screenData.stage"
              @click="selectedPublisher(screenData.stage, item)"
              :key="key">{{ item.value }}
              </li>
            </ul>
          </div>
          <div class="vm-require-screen-item">
            <h5>最近日期</h5>
            <ul class="vm-require-screen-list">
              <li
              :class="{'now': item.isActive}"
              v-for="(item, key) in screenData.datetime"
              @click="selectedPublisher(screenData.datetime, item)"
              :key="key">{{ item.value }}
              </li>
            </ul>
          </div>
          <div class="vm-require-screen-item">
            <h5>发布方</h5>
            <ul class="vm-require-screen-list">
              <li
                :class="{'now': item.isActive}"
                v-for="(item, key) in screenData.companyType"
                @click="selectedPublisher(screenData.companyType, item)"
                :key="key">
                {{ item.value }}
              </li>
            </ul>
          </div>
          <div class="vm-require-screen-item" v-if="false">
            <h5>单位名称</h5>
            <ul class="vm-require-screen-company">
              <li>
                <input type="text" v-model="companyName" placeholder="请输入单位名称">
              </li>
            </ul>
          </div>
        </div>
      </div>
      <div class="vm-screen-footer">
          <mt-button type="default" @click="resetData">重置</mt-button>
          <mt-button type="danger" @click="confirmData">确认</mt-button>
        </div>
    </mt-popup>

    <!-- 需求信息筛选 -->
    <mt-popup
      class="vm-screen-warp"
      v-model="popupVisible"
      position="right"
      v-if="type == 'requirePage'"
    >
      <div class="vm-require-warp" ref="popupWarpper">
        <div class="content">
          <div class="vm-require-screen-item">
            <h5>发布人</h5>
            <ul class="vm-require-screen-list">
              <li
              :class="{'now': item.isActive}"
              v-for="(item, key) in screenData.companyType"
              @click="selectedPublisher(screenData.companyType, item)"
              :key="key"> {{ item.value }}
              </li>
            </ul>
          </div>
          <div class="vm-require-screen-item">
            <h5>采购方式</h5>
            <ul class="vm-require-screen-list">
              <li
              :class="{'now': item.isActive}"
              v-for="(item, key) in screenData.type"
              @click="selectedPublisher(screenData.type, item)"
              :key="key">{{ item.value }}
              </li>
            </ul>
          </div>
          <div class="vm-require-screen-item">
            <h5>阶段</h5>
            <ul class="vm-require-screen-list">
              <li
              :class="{'now': item.isActive}"
              v-for="(item, key) in screenData.state"
              @click="selectedPublisher(screenData.state, item)"
              :key="key">{{ item.value }}
              </li>
            </ul>
          </div>
          <div class="vm-require-screen-item">
            <h5>发布日期</h5>
            <ul class="vm-require-screen-time">
              <li @click="openPicker(1)">{{startDay | dateFormat}}</li>
              <li></li>
              <li @click="openPicker(2)">{{endDay | dateFormat}}</li>
            </ul>
          </div>
          <div class="vm-require-screen-item">
            <h5>单位名称</h5>
            <ul class="vm-require-screen-company">
              <li>
                <input type="text" v-model="companyName" placeholder="请输入单位名称">
              </li>
            </ul>
          </div>
        </div>
      </div>
      <div style="position: absolute;" class="vm-screen-footer">
          <mt-button type="default" @click="resetData">重置</mt-button>
          <mt-button type="danger" @click="confirmData">确认</mt-button>
        </div>
    </mt-popup>

    <!-- 询源分析筛选 -->
    <mt-popup
      class="vm-screen-warp"
      v-model="popupVisible"
      position="right"
      v-if="type == 'sourcePage'"
    >
      <div class="vm-require-warp" ref="popupWarpper">
        <div class="content">
          <div class="vm-require-screen-item">
            <h5>月份</h5>
            <ul class="vm-require-screen-list">
              <li
                :class="{'now': item.isActive}"
                :key="key"
                v-for="(item, key) in screenData.month"
                @click="selectedPublisher(screenData.month, item)">
                {{ item.month }}
              </li>
            </ul>
          </div>
        </div>
      </div>
      <div class="vm-screen-footer">
        <mt-button type="default" @click="resetData">重置</mt-button>
        <mt-button type="danger" @click="confirmData">确认</mt-button>
      </div>
    </mt-popup>
    <!-- 时间插件 -->
    <mt-datetime-picker
      type="date"
      year-format="{value} 年"
      month-format="{value} 月"
      date-format="{value} 日"
      ref="picker"
      v-model="pickerValue"
      @confirm="confirm">
    </mt-datetime-picker>
  </div>
</template>

<script>
  import BScroll from 'better-scroll';
  import {CommonSearchPopup} from '@/utils/vm-common-searchPopup.js'
  import {userInfoByArguments} from '@/utils/userHandler.js'
  import {source_getCompanywarehouseinfo} from '@/api/statistics_analysis'
  import { mapState } from 'vuex'

  export default {
    data() {
      return {
        popupVisible: false, // 是否显示弹框
        startDay: '开始日期', // 开始时间
        endDay: '结束日期', // 结束事件
        companyName: '', // 公司名称
        pickerValue: false, //
        pickerType: null,
        monthIndex: 0, // 月份索引
        storageIndex: 0, // 仓库索引
      }
    },
    created() {},
    props: ["ScreenData", "type","Warehouse"],
    computed: {
      screenData() {
        return this.ScreenData;
      },
      ...mapState({
        index: state => state.statistics_analysis.index
      })
    },
    watch: {
      popupVisible: {
        handler(newV) {
         newV && this.initScroll();
        }
      }
    },
    mounted () {},
    methods: {
      // 测试
      test (list, index) {
        console.log(window.vm.$set(list[index], 'active', true));
      },
      // 初始化
      init(_type) {
        window.commonPopup = new CommonSearchPopup(this, _type);
      },
      // 用户选择功能
      selectedPublisher(data, item) {
        window.commonPopup.getSelectorData(data, item);
      },
      // 重置数据
      resetData() {
        window.commonPopup.resetPopupData();
      },
      // 点击确定提交
      confirmData() {
        window.commonPopup.confirmData();
      },
      // 打开时间插件
      openPicker(type) {
        this.pickerType = type;
        this.$refs.picker.open();
      },
      confirm(time) {
        let pickerType = this.pickerType;
        if (pickerType == 1) {
          this.startDay = this.$moment(time).format("YYYY-MM-DD");
        } else if (pickerType == 2) {
          this.endDay = this.$moment(time).format("YYYY-MM-DD");
        }
        this.pickerType = null;
      },
      // 改变月份状态
      upMonthData(index, flag) {
        this.screenData.month[index].isActive = flag;
      },
      // 选择仓库状态
      upStorageState(index, flag) {
        this.screenData.warehouse[index].isActive = flag;
      },
      // 操作模态框
      handlerPopup(falg) {
        this.popupVisible = falg;
      },
      initScroll(){
        this.$nextTick(()=>{
          if(!this.myscroll){
              this.myscroll = new BScroll(this.$refs.popupWarpper,{
                click: true
              });
          }else{
              this.myscroll.refresh();
          }
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
  .vm-screen-warp {
    width: 600px;
    margin-top: 128px;
    height: 100%;
    .vm-require-warp {
      overflow: scroll;
      height: calc( 100% - 241px );
      position: relative;
      .vm-require-screen-item {
        display: flex;
        flex-direction: column;
        margin-left: 40px;
        padding-bottom: 40px;
        &:last-child {
          padding-bottom: 113px;
        }
        h5 {
          color: #000;
          font-size: 26px;
          display: flex;
          justify-content: flex-start;
          align-items: center;
          height: 65px;
          &::before {
            content: '';
            width: 5px;
            height: 24px;
            background-color: #f34c4f;
            display: inline-block;
            margin-right: 18px;
          }
        }
        ul.vm-require-screen-list {
          display: flex;
          flex-wrap: wrap;
          li {
            background-color: #eeeeee;
            width: 170px;
            height: 60px;
            font-size: 24px;
            color: #999999;
            display: flex;
            margin-right: 10px;
            align-items: center;
            justify-content: center;
            border-radius: 10px; /* no */
            margin-bottom: 10px;
            position: relative;
            &.now {
              background-color: #ffffff;
              color: #d8271b;
              border: 1px solid #d8271b; /* no */
              &::before {
                content: '√';
                display: flex;
                align-items: center;
                margin-right: 10px;
              }
            }
          }
        }
        ul.vm-require-screen-time {
          display: flex;
          align-items: center;
          li {
            margin-right: 30px;
            width: 250px;
            height: 55px;
            border: 1px solid #eeeeee; /* no */
            border-radius: 15px; /* no */
            display: flex;
            justify-content: center;
            align-items: center;
            color: #999;
            font-size: 26px;
            background-color: #fff;
            &:nth-child(2) {
              width: 20px;
              height: 4px;
              background-color: #eeeeee;
            }
          }
        }
        ul.vm-require-screen-company {
          display: flex;
          li {
            flex: 1;
            margin-right: 20px;
            input {
              font-size: 26px;
              border-radius: 15px; /* no */
              height: 55px;
            }
          }
        }
        ul.saa-search-data.com-box {
          & > li.active {
            color: #D9271B;
            border: 1px solid #D9271B; /* no */
          }
          & > li {
            height: 0.8rem;
            padding: 0 0.373333rem;
            border: 1px solid #666666; /* no */
            margin: 0.266666rem 0.266666rem 0 0;
            border-radius: 15px;
            line-height: 0.773333rem;
            color: #A0A0A0;
            text-align: left;
            &:first-child {
              width: 1.866666rem;
              text-align: center;
            }
          }

        }
      }
    }
    .vm-screen-footer {
      background: #ffffff;
      border-top: 1px solid #eeeeee; /* no */
      position: absolute;
      bottom: 90px;
      width: 100%;
      left: 0;
      height: 113px;
      border-top: 1px solid #eee; /* no */
      display: flex;
      justify-content: space-between;
      button {
        flex: 1;
        width: 50%;
        height: 78px;
        margin: 21px 20px 12px 30px;
        border-radius: 10px; /* no */
        &:first-child {
          border: 1px solid #d9271b; /* no */
          background-color: #fff;
          color: #d8261d;
          font-size: 24px;
        }
        &:last-child {
          background-color: #f34c4f;
          color: #fff;
          font-size: 24px;
        }
      }
    }
  }
</style>
